package cn.yuyin.item;

import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import cn.yuyin.main.Main;
import cn.yuyin.utile.FormatData;

public class TextBoxItem3 extends Item{
	String name;
	Vector texts;
	DateBox db;
	public TextBoxItem3(int index,int x, int y, String name,String text) {
		super(x, y, text);
		this.index = index;
		this.name = name;
		db=new DateBox(name,text);
		width = Main.WIDTH-Main.margin - 40;
		height = Main.font.getHeight()+5;
		endX = this.x+width;
		endY = this.y;
		db.item = this;
	}
	
	private void setIsHaveFouse(){
		if(index==Main.superPage.index){
			ishaveFouse = true;
		}else{
			ishaveFouse = false;
		}
	}

	public void paint(Graphics g) {
		texts = FormatData.splitStr(Main.font, text, Main.WIDTH - Main.margin
				- 40 - Main.font.stringWidth(name));
		int color = g.getColor();
		setIsHaveFouse();
		if (ishaveFouse) {
			g.setColor(0xffffff);
			g.fillRoundRect(x + Main.font.stringWidth(name) + 10, y, Main.WIDTH - Main.margin
					- x * 2 - Main.font.stringWidth(name) - 10, height, 8, 8);
			g.setColor(0xB5C3FF);
			g.drawRoundRect(x + Main.font.stringWidth(name) + 10, y, Main.WIDTH - Main.margin 
					- x * 2 - Main.font.stringWidth(name) - 10, height, 8, 8);
			g.setColor(0x6396e7);
			g.drawRoundRect(x + Main.font.stringWidth(name) + 10, y, Main.WIDTH - Main.margin
					- x * 2 - Main.font.stringWidth(name) - 10, height, 8, 8);
			g.drawRoundRect(x + Main.font.stringWidth(name) + 10 + 1, y + 1, Main.WIDTH - Main.margin
					- (x * 2 + 2) - Main.font.stringWidth(name) - 10, height - 2, 8, 8);
			g.setColor(0x35599);
			g.drawString(name, x + 5, y + 5, Graphics.LEFT | Graphics.TOP);
			g.setColor(0xbdbebd);
			for (int i = 0; i < texts.size(); i++) {
				if (5 + Main.font.getHeight() * i + Main.font.getHeight() > height) {
					break;
				}
				g.drawString(texts.elementAt(i).toString(), x + 1 + (Main.font.stringWidth(name) + 15) + 5,
						y + 3 + Main.font.getHeight() * i, Graphics.LEFT | Graphics.TOP);
			}
		} else {
			g.setColor(0xffffff);
			g.fillRoundRect(x + Main.font.stringWidth(name) + 10, y, Main.WIDTH
					- Main.margin - x * 2 - Main.font.stringWidth(name) - 10,
					height, 8, 8);
			g.setColor(0xB5C3FF);
			g.drawRoundRect(x + Main.font.stringWidth(name) + 10, y, Main.WIDTH
					- Main.margin - x * 2 - Main.font.stringWidth(name) - 10,
					height, 8, 8);
			g.setColor(0x35599);
			g.drawString(name, x + 5, y + 5, Graphics.LEFT | Graphics.TOP);
			g.setColor(0xbdbebd);
			for (int i = 0; i < texts.size(); i++) {
				if (5 + Main.font.getHeight() * i + Main.font.getHeight() > height) {
					break;
				}
				g.drawString(texts.elementAt(i).toString(), x + 1 + (Main.font.stringWidth(name) + 15) + 5,
						y + 3 + Main.font.getHeight() * i, Graphics.LEFT | Graphics.TOP);
			}
		}
		g.setColor(color);
	}

	public void keyPressed(int keyCode) {

	}

	public void keyReleased(int keyCode) {
		switch (keyCode) {
		case Main.key_OK:
			if (ishaveFouse)
				Main.display.setCurrent(db);
			break;
		}
	}

	public void pointerPressed(int x, int y) {
		if (x > this.x && x < x + width && y > this.y && y < y + height) {
			Main.display.setCurrent(db);
		}
	}

	public void pointerReleased(int x, int y) {

	}
}
